package com.igeek.yygh.controller;

import com.igeek.yygh.model.cmn.Dict;
import com.igeek.yygh.result.Result;
import com.igeek.yygh.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * TODO
 *
 * @author Guzhenghui
 * @since 2024/8/19
 */
@RestController
@RequestMapping("/admin/dict")
@Slf4j
@Api(tags = "数据字典接口")
@CrossOrigin
public class DictController {
    @Autowired
    private DictService dictService;

    @ApiOperation("树形懒加载查询数据字典列表")
    @GetMapping("/list/{id}")
    public Result FindList(@PathVariable("id") Long id){
        List<Dict> list=dictService.findAllData(id);
        return Result.ok(list);
    }
    @ApiOperation("数据字典导出")
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response) throws IOException {
        dictService.exportData(response);
    }

    @ApiOperation("数据字典导入")
    @PostMapping("importData")
    public void importData(MultipartFile multipartFile) throws IOException {
        dictService.importData(multipartFile);
    }
}
